﻿using Microsoft.AspNetCore.Mvc;
using WCS_Entity.Dto;
using WCS_Entity.Dto.RcsDto;
using WCS_Service.Interface;

namespace WCS.Controllers
{
    /// <summary>
    /// RCS服务管理接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class RcsServiceController : ControllerBase
    {
        private readonly IRcsService _rcsService;
        public RcsServiceController(IRcsService rcsService)
        {
            _rcsService = rcsService;
        }
        /// <summary>
        /// 查询指定RCS的服务信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebApiCallBack> QueryRcsServiceAsync(int id)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _rcsService.QueryRcsAsync(id);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "Rcs服务获取失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
        /// <summary>
        /// 查询所有RCS服务信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> QueryAllRcsServiceAsync()
        {
            var result = new WebApiCallBack();
            var dtoInfos = await _rcsService.QueryAllRcsAsync();
            if (dtoInfos is null)
            {
                result.status = false;
                result.msg = "获取所有Rcs服务失败";
                return result;
            }
            result.data = dtoInfos;
            return result;
        }
        /// <summary>
        /// 删除指定的RCS服务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<WebApiCallBack> DeleteRcsServiceAsync(int id)
        {
            var result = new WebApiCallBack();
            result.status = await _rcsService.DeleteRcs(id);
            result.msg = result.status ? "删除成功":"删除失败";
            return result;
        }
        /// <summary>
        /// 创建RCS服务信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> CreateRcsServiceAsync([FromBody] CreateRcsDto dto)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _rcsService.CreateRcsAsync(dto);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "创建所有Rcs服务失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
        /// <summary>
        /// 更新RCS服务信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> UpdateRcsServiceAsync([FromBody] UpdateRcsDto dto)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _rcsService.UpdateRcsAsync(dto);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "更新所有Rcs服务失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
    }
}
